<?php
/**
 * Created by PhpStorm.
 * User: adophper
 * Date: 2018-03-20
 * Time: 17:09
 */
namespace frontend\controllers;

use common\models\ExhibitionHall;
use common\services\ExhibitionHallServices;
use common\services\ExhibitionServices;
use frontend\base\BaseFrontController;

class HallController extends BaseFrontController
{
    /**
     * 展馆首页
     * @return string
     */
    public function actionIndex()
    {
        $service = new ExhibitionHallServices();
        $params = array(
//            'recommend' => 1,
            'limit' => 5,
            'order' => 'recommend desc,order desc,id desc'
        );
        $hot = $service->getSearchArray($params);
        $params = array(
            'limit' => 9
        );
        $banner = $service->getSearchArray($params);
        //城市
        $city = $service->getHallCity(0);

        return $this->render('index', [
            'hot' => $hot,
            'banner' => $banner,
            'city' => $city,
        ]);
    }

    /**
     * 展馆列表
     * @param string $id
     * @return string
     */
    public function actionList(){
        $regionId = \Yii::$app->request->get('regionId');
        $service = new ExhibitionHallServices();
        $params = array(
            'status' => ExhibitionHall::STATUS_FLAG_NORMAL,
            'defaultPageSize' => 6,
            'order' => 'order desc,id desc',
            'region_id' => $regionId,
            'searchExhibition' => true,
        );
        $dataProvider = $service->search($params);

        return $this->renderAjax('list', [
            'regionId' => $regionId,
            'dataProvider' => $dataProvider,
        ]);
    }

    /**
     * 展馆详情
     * @param $id
     * @return string
     */
    public function actionDetail($id){
        $service = new ExhibitionHallServices();
        $data = $service->getDetail($id);

        return $this->render('detail', [
            'data' => $data,
            'model' => $data['model'],
        ]);
    }

}